using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class SerializableDictionary<Tkey,Tvalue>:Dictionary<Tkey,Tvalue>,ISerializationCallbackReceiver
{
    [SerializeField]private List<Tkey> keyList = new List<Tkey>();
    [SerializeField]private List<Tvalue> valueList = new List<Tvalue>();
 
    public void OnBeforeSerialize()
    {
        keyList.Clear();
        valueList.Clear(); 
        foreach(KeyValuePair<Tkey,Tvalue>pair in this)
        {
            keyList.Add(pair.Key);
            valueList.Add(pair.Value);
        }
    }
    public void OnAfterDeserialize()
    {
        this.Clear();
        if (keyList.Count != valueList.Count)
            return;
        for(int i = 0;i< keyList.Count; i++)
        {
            this.Add(keyList[i], valueList[i]);
        }
    }

}
